package engine.data;

import util.ArrayList;
import util.List;

public final class Building {

	public static final byte NONE = -1;

	/*
	 * A city without an AQUEDUCT may not grow beyond a size of 10. OK
	 */
	public static final byte AQUEDUCT = 0;

	/*
	 * Luxuries and tax revenue increased by 50%. OK
	 */
	public static final byte BANKS = 1;

	/*
	 * New units are Veterans when produced at a city containing a BARRACKS,
	 * giving them advantages in combat against similar, non-Veteran units. OK
	 */
	public static final byte BARRACKS = 2;

	public static final byte BARRACKS_2 = 3;

	public static final byte BARRACKS_3 = 4;

	/*
	 * Four unhappy people are made content.
	 */
	public static final byte CATHEDRAL = 5;

	/*
	 * Defense bonus = +200%; no population loss when attacked.
	 */
	public static final byte CITY_WALLS = 6;

	/*
	 * Three unhappy people changed to content in city.
	 */
	public static final byte COLOSSEUM = 7;

	/*
	 * Reduces corruption in city by 50%.
	 */
	public static final byte COURTHOUSE = 8;

	/*
	 * Production is increased by 50%. OK
	 */
	public static final byte FACTORY = 9;

	/*
	 * Only 50% of food storage is used to create new population. Protects the
	 * city against the disaster of Famine. OK
	 */
	public static final byte GRANARY = 10;

	/*
	 * Factory production is increased by 50%; existing pollution is reduced.
	 * NOK
	 */
	public static final byte HYDRO_PLANT = 11;

	/*
	 * Knowledge production increased by 50%. OK
	 */
	public static final byte LIBRARY = 12;

	/*
	 * Production is increased by 100%. OK
	 */
	public static final byte MANUFACTURING_PLANT = 13;

	/*
	 * Luxuries and tax revenues are increased by 50%. OK
	 */
	public static final byte MARKETPLACE = 14;

	/*
	 * Reduces pollution produced by city population.
	 */
	public static final byte MASS_TRANSIT = 15;

	/*
	 * Factory production is increased by 50%; low pollution level -- risk of
	 * MELTDOWN! NOK
	 */
	public static final byte NUCLEAR_PLANT = 16;

	/*
	 * A center of administration and governmental power. The further cities are
	 * from a PALACE, the more corruption is likely.
	 */
	public static final byte PALACE = 17;

	/*
	 * Factory production is increased by 50%; high pollution level. NOK
	 */
	public static final byte POWER_PLANT = 18;

	/*
	 * Reduces industrial pollution in city by two-thirds.
	 */
	public static final byte RECYCLING_CENTER = 19;

	/*
	 * Protects city from nuclear weapons.
	 */
	public static final byte SDI_DEFENSE = 20;

	/*
	 * Spaceship COMPONENTS have a mass of 400 tons each and a spaceship may
	 * include a maximum of eight of each type.
	 */
	public static final byte SPACE_COMPONENT = 21;

	/*
	 * Habitation and Life Support MODULES have a mass of 1,600 tons and Solar
	 * Panel MODULES have a mass of 400 tons. A spaceship may include a maximum
	 * of four MODULES of each type.
	 */
	public static final byte SPACE_MODULE = 22;

	/*
	 * Spaceship STRUCTURAL parts each have a mass of 100 tons and a spaceship
	 * may include up to thirty-nine STRUCTURAL pieces.
	 */
	public static final byte SPACE_STRUCTURAL = 23;

	/*
	 * Unhappy people are made content (1 if you have Ceremonial Burial, 2 if
	 * Mysticism). This is doubled if you have the Oracle Wonder.
	 */
	public static final byte TEMPLE = 24;

	/*
	 * Knowledge production increased by 50%. OK
	 */
	public static final byte UNIVERSITY = 25;

	/*
	 * Allows the construction of Spaceships. Makes all cities on the map
	 * visible.
	 */
	public static final byte APOLLO_PROGRAM = 26;

	/*
	 * +1 trade per trade square in the city, until the development of
	 * ELECTRICITY. OK
	 */
	public static final byte COLOSSUS = 27;

	/*
	 * Doubles knowledge production in city, until the development of the
	 * AUTOMOBILE. OK
	 */
	public static final byte COPERNICUS_OBSERVATORY = 28;

	/*
	 * +1 happy citizen in each city.
	 */
	public static final byte CURE_FOR_CANCER = 29;

	/*
	 * Two immediate civilization advances.
	 */
	public static final byte DARWINS_VOYAGE = 30;

	/*
	 * Gives you any technology that two other civilizations possess, until the
	 * development of the UNIVERSITY.
	 */
	public static final byte GREAT_LIBRARY = 31;

	/*
	 * Other civilizations always offer to make peace with you, until the
	 * development of GUNPOWDER.
	 */
	public static final byte GREAT_WALL = 32;

	/*
	 * +1 happy face in each city, until the development of INVENTION.
	 */
	public static final byte HANGING_GARDENS = 33;

	/*
	 * Supplies Hydro power to all cities on the continent.
	 */
	public static final byte HOOVER_DAM = 34;

	/*
	 * Increases the benefit of LIBRARIES+UNIVERSITIES, until the development of
	 * NUCLEAR FISSION.
	 */
	public static final byte ISAAC_NEWTONS_COLLEGE = 35;

	/*
	 * Decreases unhappy people on continent by 2 per city.
	 */
	public static final byte JS_BACHS_CATHEDRAL = 36;

	/*
	 * Increases sea movement rates by 1 MP, until the development of MAGNETISM.
	 */
	public static final byte LIGHTHOUSE = 37;

	/*
	 * Increases sea movement by 1 MP.
	 */
	public static final byte MAGELLANS_EXPEDITION = 38;

	/*
	 * Allows the construction of nuclear weapons.
	 */
	public static final byte MANHATTAN_PROJECT = 39;

	/*
	 * Increases the effect of CATHEDRALS, until the development of COMMUNISM.
	 */
	public static final byte MICHELANGELOS_CHAPEL = 40;

	/*
	 * Doubles the effects of Temples, until the development of RELIGION.
	 */
	public static final byte ORACLE = 41;

	/*
	 * Allows change of government without Anarchy; Makes available all forms of
	 * government. Both of these effects last until the development of
	 * COMMUNISM.
	 */
	public static final byte PYRAMIDS = 42;

	/*
	 * Increases knowledge production in all cities by 50%. OK
	 */
	public static final byte SETI_PROGRAM = 43;

	/*
	 * All unhappy people in city are content, until the development of
	 * ELECTRONICS.
	 */
	public static final byte SHAKESPEARES_THEATRE = 44;

	/*
	 * Other civilizations always offer to make peace with you.
	 */
	public static final byte UNITED_NATIONS = 45;

	/*
	 * Reduces unhappy people by one per unit not in home city under Republic or
	 * Democracy.
	 */
	public static final byte WOMENS_SUFFRAGE = 46;

	public static final byte SIZE = 47;

	private static final byte[] REQUIRED_BUILDING = { -1, MARKETPLACE, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, /*-1,*/
	-1, FACTORY, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, LIBRARY, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1 - 1, -1, -1,
			-1, -1, -1, -1, -1, -1, -1, -1, -1 };

	private static final byte[] REQUIRED_TECH = { Technology.CONSTRUCTION, Technology.BANKING, -1, Technology.GUNPOWDER,
			Technology.COMBUSTION, Technology.RELIGION, Technology.MASONRY, Technology.CONSTRUCTION,
			Technology.CODE_OF_LAWS, Technology.INDUSTRIALIZATION, Technology.POTTERY, Technology.ELECTRONICS, -1,
			Technology.ROBOTICS, Technology.CURRENCY, Technology.MASS_PRODUCTION, Technology.NUCLEAR_POWER,
			Technology.MASONRY, Technology.REFINING, Technology.RECYCLING, Technology.SUPERCONDUCTOR,
			Technology.PLASTICS, Technology.ROBOTICS, Technology.SPACE_FLIGHT, Technology.CEREMONIAL_BURIAL,
			Technology.UNIVERSITY, Technology.SPACE_FLIGHT, Technology.BRONZE_WORKING, Technology.ASTRONOMY,
			Technology.GENETIC_ENGINEERING, Technology.RAILROAD, Technology.LITERACY, Technology.MASONRY,
			Technology.POTTERY, Technology.ELECTRONICS, Technology.THEORY_OF_GRAVITY, Technology.RELIGION,
			Technology.MAP_MAKING, Technology.NAVIGATION, Technology.NUCLEAR_FISSION, Technology.RELIGION,
			Technology.MYSTICISM, Technology.MASONRY, Technology.COMPUTERS, Technology.MEDICINE, Technology.COMMUNISM,
			Technology.INDUSTRIALIZATION };

	private static final byte[] OBSOLETE_BY = { Technology.NONE, Technology.NONE, Technology.GUNPOWDER,
			Technology.COMBUSTION, Technology.NONE, Technology.NONE, Technology.NONE, Technology.NONE, Technology.NONE,
			Technology.NONE, Technology.NONE, Technology.NONE, Technology.NONE, Technology.NONE, Technology.NONE,
			Technology.NONE, Technology.NONE, Technology.NONE, Technology.NONE, Technology.NONE, Technology.NONE,
			Technology.NONE, Technology.NONE, Technology.NONE, Technology.NONE, Technology.NONE, Technology.NONE,
			Technology.ELECTRICITY, Technology.AUTOMOBILE, Technology.NONE, Technology.NONE, Technology.UNIVERSITY,
			Technology.GUNPOWDER, Technology.INVENTION, Technology.NONE, Technology.NUCLEAR_FISSION, Technology.NONE,
			Technology.MAGNETISM, Technology.NONE, Technology.NONE, Technology.COMMUNISM, Technology.RELIGION,
			Technology.COMMUNISM, Technology.NONE, Technology.ELECTRONICS, Technology.NONE, Technology.NONE };

	private static final short[] PP = { 120, 120, 40, 40, 40, 160, 120, 100, 80, 200, 60, 240, 80, 320, 80, 160, 240,
			200, 160, 200, 160, 320, 80, 40, 160, 600, 200, 300, 600, 300, 300, 300, 300, 600, 400, 400, 200, 400, 600,
			300, 300, 300, 600, 400, 600, 600, 600 };

	private static final byte[] MC = { 2, 3, 1, 2, 3, 3, 2, 4, 1, 4, 1, 4, 1, 6, 1, 4, 2, 0, 4, 2, 4, 0, 0, 0, 1, 3, 0,
			0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 };

	private static final String[] NAME = { "Aqueduct", "Bank", "Barracks", "Barracks", "Barracks", "Cathedral",
			"City Walls", "Colosseum", "Courthouse", "Factory", "Granary", "Hydro Plant", "Library", "Mfg. Plant",
			"Marketplace", "Mass Transit", "Nuclear Plant", "Palace", "Power Plant", "Recycling Center", "SDI Defense",
			"Space Component", "Space Module", "Space Structural", "Temple", "University", "Apollo Program",
			"Colossus", "Copernicus Observatory", "Cure For Cancer", "Darwin's Voyage", "Great Library", "Great Wall",
			"Hanging Gardens", "Hoover Dam", "Isaac Newton's College", "J.S. Bach's Cathedral", "Lighthouse",
			"Magellan's Expedition", "Manhattan Project", "Michelangelo's Chapel", "Oracle", "Pyramids",
			"SETI Program", "Shakespeare's Theatre", "United Nations", "Women's Suffrage" };

	private static final String[] INFO = {
			"A city without an AQUEDUCT \n" + "may not grow beyond a size \n" + "of 10.",
			"Luxuries and tax revenue \n" + "increased by 50%.",
			"New units are Veterans \n" + "when produced at a city \n" + "containing a BARRACKS \n"
					+ "giving them advantages in \n" + "combat against similar, \n" + "non-Veteran units.",
			"New units are Veterans \n" + "when produced at a city \n " + "containing a BARRACKS \n"
					+ "giving them advantages in \n" + "combat against similar, \n" + "non-Veteran units.",
			"New units are Veterans \n" + "when produced at a city \n" + "containing a BARRACKS \n"
					+ "giving them advantages in \n" + "combat against similar, \n" + "non-Veteran units.",
			"Four unhappy people are \n" + "made content.",
			"Defense bonus = +200%; no \n" + "population loss when \n" + "attacked.",
			"Three unhappy people \n" + "changed to content in city.",
			"Reduces corruption in city\n" + "by 50%.",
			"Production is increased by\n" + "50%.",
			"Only 50% of food storage \n" + "is used to create new \n" + "population. Protects the \n"
					+ "city against the disaster\n" + "of Famine.",
			"Factory production is \n" + "increased by 50%; \n" + "existing pollution is \n" + "reduced.",
			"Knowledge production is\n" + "increased by 50%.",
			"Production is increased by\n" + "100%.",
			"Luxuries and tax \n" + "revenues are increased by\n" + "50%.",
			"Reduces pollution \n" + "produced by city \n" + "population.",
			"Factory production is \n" + "increased by 50%; low \n" + "pollution level -- risk \n" + "of MELTDOWN!",
			"A center of administration\n" + "and governmental power. \n" + "The further cities are \n"
					+ "from a PALACE, the more \n" + "corruption is likely.",
			"Factory production is \n" + "increased by 50%; high \n" + "pollution level.",
			"Reduces industrial \n" + "pollution in city by \n" + "two-thirds.",
			"Protects city from \n" + "nuclear weapons.",
			"Spaceship COMPONENTS \n" + "have a mass of 400 tons \n" + "each and a spaceship may \n"
					+ "include a maximum of eight\n" + " of each type.",
			"Habitation and Life \n" + "Support MODULES have a \n" + "mass of 1,600 tons and \n"
					+ "Solar Panel MODULES have a\n" + "mass of 400 tons. A \n" + "spaceship may include a \n"
					+ "maximum of four MODULES of\n" + "each type.",
			"Spaceship STRUCTURAL parts\n" + "each have a mass of 100 \n" + "tons and a spaceship may \n"
					+ "include up to thirty-nine \n" + "STRUCTURAL pieces.",
			"Unhappy people are made \n" + "content (1 if you have \n" + "Ceremonial Burial, 2 if \n"
					+ "Mysticism). This is \n" + "doubled if you have the \n" + "Oracle Wonder.",
			"Knowledge production is \n" + "increased by 50%.",
			"Allows the construction of\n" + "Spaceships. Makes all \n" + "cities on the map visible.",
			"+1 trade per trade square \n" + "in the city, until the \n" + "development of ELECTRICITY.",
			"Doubles knowledge \n" + "production in city, until \n" + "the development of the \n" + "AUTOMOBILE.",
			"+1 happy citizen in each \n" + "city.",
			"Two immediate civilization\n" + "advances.",
			"Gives you any technology \n" + "that two other \n" + "civilizations possess, \n"
					+ "until the development of \n" + "the UNIVERSITY.",
			"Other civilizations always\n" + "offer to make peace with \n" + "you, until the development\n"
					+ "of GUNPOWDER.",
			"+1 happy face in each city,\n" + "until the development of \n" + "INVENTION.",
			"Supplies Hydro power to \n" + "all cities on the \n" + "continent.",
			"Increases the benefit of \n" + "LIBRARIES+UNIVERSITIES, \n" + "until the development of \n"
					+ "NUCLEAR FISSION.",
			"Decreases unhappy people \n" + "on continent by 2 per city.",
			"Increases sea movement \n" + "rates by 1 MP, until the \n" + "development of MAGNETISM.",
			"Increases sea movement by \n" + "1 MP.",
			"Allows the construction of\n" + "nuclear weapons.",
			"Increases the effect of \n" + "CATHEDRALS, until the \n" + "development of COMMUNISM.",
			"Doubles the effects of \n" + "Temples, until the \n" + "development of RELIGION.",
			"Allows change of \n" + "government without \n" + "Anarchy; Makes available \n"
					+ "all forms of government. \n" + "Both of these effects last\n" + "until the development of \n"
					+ "COMMUNISM.", "Increases knowledge \n" + "production in all cities \n" + "by 50%.",
			"All unhappy people in city\n" + "are content, until the \n" + "development of ELECTRONICS.",
			"Other civilizations always\n" + "offer to make peace with \n" + "you." };

	private Building() {
		// no constructor
	}

	public static String getName(final byte id) {
		return NAME[id];
	}

	public static String getInfo(final byte id) {
		return INFO[id];
	}

	public static byte getMC(final byte id) {
		return MC[id];
	}

	public static short getPP(final byte id) {
		return PP[id];
	}

	public static boolean isObsolete(final byte id, final Player player) {
		return !player.technologies.contains(new Byte(OBSOLETE_BY[id]));

	}

	public static List getPossibleBuildingIds(final Player player, final City city) {
		List ret = new ArrayList();
		for (byte i = 0; i < SIZE; i++) {
			if (!city.buildingRoster.contains(new Byte(i))
					&& (REQUIRED_TECH[i] == Technology.NONE || player.technologies.contains(new Byte(REQUIRED_TECH[i])))
					&& (REQUIRED_BUILDING[i] == NONE || city.buildingRoster.contains(new Byte(REQUIRED_BUILDING[i])))
					&& (OBSOLETE_BY[i] == Technology.NONE || !player.technologies.contains(new Byte(
							REQUIRED_TECH[OBSOLETE_BY[i]]))))
				ret.add(new Byte(i));
		}
		return ret;
	}
}
